package Operation;

import bookk.Book;
import bookk.BookList;

import java.util.Scanner;

public class DelOpertation implements IOperation{
    /**
     * @param booklist
     */
    @Override
    public void work(BookList booklist) {
        System.out.println("请输入要删除的书");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int size = booklist.getUsesize();
        int pos = -1;
        int i =0;
        for ( ; i < size; i++) {
            Book book = booklist.getBooks(i);
            if(booklist.getBooks().equals(name)){
                pos = i;
                break;
            }
        }
        if(size==i){
            System.out.println("没有找到要删除的书");
            return ;
        }
        int j = pos;
        for(;j<size-1;j++){
            Book book = booklist.getBooks(j+1);
            booklist.setBooks(j,book);
        }
        booklist.setBooks(j,null);
        booklist.setUsesize(size-1);
        System.out.println("删除成功");
    }
}
